package initialize

import (
	sentinel "github.com/alibaba/sentinel-golang/api"
	"github.com/alibaba/sentinel-golang/core/flow"
	"go.uber.org/zap"
)

func InitSentinel() {
	//先初始化sentinel
	err := sentinel.InitDefault()
	if err != nil {
		zap.S().Fatalf("初始化sentinel 异常: %v", err)
	}
	//配置限流规则
	_, err = flow.LoadRules([]*flow.Rule{
		{
			Resource:               "some-test",
			TokenCalculateStrategy: flow.Direct, //直接计算
			ControlBehavior:        flow.Reject, //直接拒绝
			Threshold:              2,           //如果不写StatIntervalInMs 默认以秒控制秒钟 控制的次数Threshold来控制的 默认超过了Threshold次数就进行限流，
		},
	})
	if err != nil {
		zap.S().Fatalf("加载规则失败: %v", err)
	}
}
